<?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.app
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       cake
 * @subpackage    cake.app
 */
class AppController extends Controller {
	var $components = array('Auth', 'Session'); 

	function beforeFilter(){
        	$this->Auth->authenticate = ClassRegistry::init('User');
            $user = $this->Auth->user();
            
            if(empty($user) && $this->params['action'] != 'login'){
			$this->redirect(array('controller' => 'users', 'action' => 'login'));
		      }
       	$this->Auth->loginAction 	= array('controller' => 'users', 'action' => 'login');
		$this->Auth->loginRedirect 	= array('controller'=>'canbos', 'action' => 'index');
		$this->Auth->loginError 	= 'Tên tài khoản hoặc mật khẩu sai';
		$this->Auth->authError 		= 'Bạn cần phải đăng nhập hệ thống để sử dụng các chức năng';
		$this->Auth->logoutRedirect = '/';
        
        
   }
   
	function beforeRender() {
		// Tạo biến curUser trong session
		//có đoạn này mới hiện dc thông tin admin ở layout/default
    	$this->set('curUser', $this->Auth->user());
	}
}
